<?php
// +----------------------------------------------------------------------
// | 麦沃德科技赋能开发者，助力中小企业发展
// +----------------------------------------------------------------------
// | Copyright (c) 2017～2024  www.wdadmin.cn    All rights reserved.
// +----------------------------------------------------------------------
// | Wdadmin系统产品软件并不是自由软件，不加密，并不代表开源，未经许可不可自由转售和商用
// +----------------------------------------------------------------------
// | Author: MY WORLD Team <bd@maiwd.cn>   www.wdadmin.cn
// +----------------------------------------------------------------------
/**
 * Class DistanceCalculations
 * Desc  距离计算Model
 * Create on 2024/11/11 15:00
 * Create by wangyafang
 */

namespace app\api\model\wddj\driver;


use app\api\model\wddj\user\operation\CostAllocation;
use think\Model;

class DistanceCalculations extends Model
{
// 表名
    protected $name = 'wddj_distance_calculations';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = true;

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;
    protected $deleteTime = false;

    protected static function init()
    {
        self::afterInsert(function ($row) {
            $total_meter = self::where('order_id',$row['order_id'])->sum('meter');
            $orderObj = (new Order())->get($row['order_id']);
            $estimated_amount_result = CostAllocation::estimated_amount($orderObj['city_id'],$total_meter,$row['order_id']);
            $orderObj->actual_amount = $estimated_amount_result['estimated_amount'];
            $orderObj->save();
        });
    }
}



 